<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>innerHTML</title>
</head>

<body>
    <button>显示时间</button>
    <div>位置</div>
    <p>位置</p>
    <script>
        var btn = document.querySelector('button');
        var div = document.querySelector('div');

        btn.onclick = function () {
            div.innerText = getDates();
        }

        function getDates() {

            var d = new Date();
            var arr = ['日', '一', '二', '三', '四', '五', '六'];
            return d.getFullYear() + '年  ' + (d.getMonth() + 1) + '月' + d.getDate() + '日   星期' + arr[d.getDay()] +
                '  ' + d.getHours() + ' : ' + d.getMinutes();
        }
        var p = document.querySelector('p');
        p.innerText = getDates();
        
    </script>
</body>

</html>